package com.ikunikun.controller.user;

import com.ikunikun.dto.OrdersPaymentDTO;
import com.ikunikun.dto.OrdersSubmitDTO;
import com.ikunikun.result.Result;
import com.ikunikun.service.OrderService;
import com.ikunikun.vo.OrderPaymentVO;
import com.ikunikun.vo.OrderSubmitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@Api(tags = "用户端订单相关接口")
@RestController("userOrderController")
@RequestMapping("/user/order")
public class OrderController {

	@Resource
	private OrderService orderService;

	@ApiOperation("用户下单")
	@PostMapping("/submit")
	public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
		log.info("用户下单信息：{}", ordersSubmitDTO);
		OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
		return Result.success(orderSubmitVO);
	}

    /**
     * 订单支付
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

	/**
	 * 用户催单
	 * @param id
	 * @return
	 */
	@GetMapping("/reminder/{id}")
	public Result<String> reminder(@PathVariable Long id){
		orderService.reminder(id);
		return Result.success();
	}
}
